﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoteServer.Member;

namespace VoteServer
{
    public class VoteData//数据+控制
    {
        private String userListPath = "E:/VS码包/其他/VoteSecond/users.dat"; //路径
        private String problemListPath = "E:/VS码包/其他/VoteSecond/problem.dat";

        private FileServer fileServer {  get;set; }//下属服务

        private List<User> userList;
        private List<Problem> problemList;

        public VoteData() {
            fileServer = new FileServer();    
        }

        
        public List<Problem> GetProblemList() {
            problemList = fileServer.ReadFile(problemListPath) as List<Problem>;
            if (problemList == null)
            {
                InitianizationProblemList();
                fileServer.WriteFile_Problem(problemList);
            }
            return problemList;
        }

        public List<User> GetUserList() {
            return userList = fileServer.ReadFile(userListPath) as List<User>;
        }

        private void InitianizationProblemList()
        {
            problemList = new List<Problem>();//初始化问题表单
            {
                new Problem
                {
                    Id = 1,
                    ProblemContent = "这是一个很严肃的问题"
                };
                new Problem
                {
                    Id = 2,
                    ProblemContent = "这是一个很严肃的问题"

                };
                new Problem
                {
                    Id = 3,
                    ProblemContent = "这是一个很严肃的问题"
                };

            };

        }

    }

}
